package com.swz.dcrm.ui.daily;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.swz.dcrm.adpter.FragmentViewPagerAdapter;
import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager.widget.ViewPager;

import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DailyFragment extends BaseFragment {

    @BindView(R.id.toolbar_title)
    TextView title;
    @BindView(R.id.tab)
    SlidingTabLayout slidingTabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tv_right)
    TextView tvRight;

    private List<String> titles;
    private List<Fragment> fragments;


    public static DailyFragment newInstance() {

        return new DailyFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public int layoutId() {
        return R.layout.fragment_daily;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        //tvRight.setText(getString(R.string.daily_history));
        title.setText(getString(R.string.daily_title));
        titles= Arrays.asList(getResources().getStringArray(R.array.daily_tab));
        fragments=new ArrayList<>();
        fragments.add(DailyTaskFragment.newInstance());
        fragments.add(DailyComeShopFragment.newInstance());
        fragments.add(DailyTargetFragment.newInstance());
        fragments.add(DaliyCustomerFragment.newInstance());
        viewPager.setAdapter(new FragmentViewPagerAdapter(getChildFragmentManager(),fragments, titles));
        slidingTabLayout.setViewPager(viewPager);
        onLoadRetry();
        return true;
    }


    @OnClick(R.id.iv_back)
    public void backClick() {
        NavHostFragment.findNavController(this).navigateUp();
    }
    @OnClick(R.id.tv_right)
    public void history(){
    go(null,R.id.action_dailyFragment_to_dailyHistoryFragment,null);
    }
}
